import Vue from 'vue'
import VueRouter from 'vue-router'
import Layout from '../layout' //布局页

Vue.use(VueRouter)
//解决重复点击左侧菜单的报错问题
const originalPush = VueRouter.prototype.push
VueRouter.prototype.push = function push(location) {
  return originalPush.call(this, location).catch(err => err)
}


export const asyncRoutes = [
  {
    path: '/system',
    component: Layout,
    meta: {
      title: "系统管理",
      icon: 'el-icon-s-custom',
    },
    name: 'system',
    children: [
      {
        path: 'user',
        name: 'user',
        component: () => import('@/views/system/user/index.vue'),
        meta: {
          title: "用户管理",
        }
      },
      {
        path: 'role',
        name: 'role',
        component: () => import('@/views/system/role/index.vue'),
        meta: {
          title: "角色管理",
        }
      },
      {
        path: 'menu',
        name: 'menu',
        component: () => import('@/views/system/menu/index.vue'),
        meta: {
          title: "菜单管理",
        }
      },
    ]
  },
  {
    path: '/logistics',
    component: Layout,
    meta: {
      title: "物流管理",
      icon: 'el-icon-truck',
    },
    name: 'logistics',
    children: [
      {
        path: 'express-outlet',
        name: 'expressOutlet',
        component: () => import('@/views/logistics/express-outlet/index.vue'),
        meta: {
          title: "快递网点管理",
        }
      },
      {
        path: 'warehouse',
        name: 'warehouse',
        component: () => import('@/views/logistics/warehouse/index.vue'),
        meta: {
          title: "物流仓库管理",
        }
      },
      {
        path: 'logistics-company',
        name: 'logisticsCompany',
        component: () => import('@/views/logistics/logistics-company/index.vue'),
        meta: {
          title: "物流公司管理",
        }
      },
    ]
  },
  {
    path: '/item',
    component: Layout,
    meta: {
      title: "物品管理",
      icon: 'el-icon-goods',
    },
    name: 'item',
    children: [
      {
        path: 'category',
        name: 'itemCategory',
        component: () => import('@/views/item/category/index.vue'),
        meta: {
          title: "物品分类管理",
        }
      },
      {
        path: 'list',
        name: 'itemList',
        component: () => import('@/views/item/list/index.vue'),
        meta: {
          title: "物品列表管理",
        }
      },
    ]
  },
  {
    path: '/insurance',
    component: Layout,
    meta: {
      title: "保险管理",
      icon: 'el-icon-umbrella',
    },
    name: 'insurance',
    children: [
      {
        path: 'company',
        name: 'insuranceCompany',
        component: () => import('@/views/insurance/company/index.vue'),
        meta: {
          title: "保险公司管理",
        }
      },
      {
        path: 'coverage',
        name: 'insuranceCoverage',
        component: () => import('@/views/insurance/coverage/index.vue'),
        meta: {
          title: "保险保额管理",
        }
      },
    ]
  },
  {
    path: '/order',
    component: Layout,
    meta: {
      title: "订单管理",
      icon: 'el-icon-document',
    },
    name: 'order',
    children: [
      {
        path: 'list',
        name: 'orderList',
        component: () => import('@/views/order/list/index.vue'),
        meta: {
          title: "快递订单列表",
        }
      },
      {
        path: 'create',
        name: 'orderCreate',
        component: () => import('@/views/order/create/index.vue'),
        meta: {
          title: "创建快递订单",
        }
      },
      {
        path: 'detail/:id',
        name: 'orderDetail',
        component: () => import('@/views/order/detail/index.vue'),
        meta: {
          title: "订单详情",
          activeMenu: '/order/list'
        },
        hidden: true
      },
    ]
  },
  {
    path: '/track',
    component: Layout,
    meta: {
      title: "物流轨迹",
      icon: 'el-icon-location',
    },
    name: 'track',
    children: [
      {
        path: 'manage',
        name: 'trackManage',
        component: () => import('@/views/track/manage/index.vue'),
        meta: {
          title: "物流轨迹管理",
        }
      },
    ]
  },
  {
    path: '/announcement',
    component: Layout,
    meta: {
      title: "系统公告",
      icon: 'el-icon-bell',
    },
    name: 'announcement',
    children: [
      {
        path: 'list',
        name: 'announcementList',
        component: () => import('@/views/announcement/list/index.vue'),
        meta: {
          title: "公告管理",
        }
      },
    ]
  },
  {
    path: '/login',
    component: () => import('@/views/login/login'),
    meta: {
      title: "欢迎登录",
    },
    hidden: true //导航菜单忽略选项
  },
]

const router = new VueRouter({
  mode: 'hash',
  base: process.env.BASE_URL,
  routes: asyncRoutes
})

export default router
